

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Retrieving counters &mdash; Apache Usergrid 1.0 documentation</title>
  

  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  

  

  
    <link rel="top" title="Apache Usergrid 1.0 documentation" href="../index.html"/>
        <link rel="next" title="Organization &amp; application management" href="../orgs-and-apps/managing.html"/>
        <link rel="prev" title="Creating &amp; incrementing counters" href="creating-and-incrementing-counters.html"/> 

  
  <script src="../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-nav-search">
        

        
          <a href="../index.html" class="icon icon-home"> Apache Usergrid
        

        
        </a>

        
          
          
            <div class="version">
              1.0
            </div>
          
        

        
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

        
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
        
          
          
              <p class="caption"><span class="caption-text">Introduction</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../introduction/overview.html">Documentation Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="../introduction/usergrid-features.html">Usergrid Features</a></li>
<li class="toctree-l1"><a class="reference internal" href="../introduction/data-model.html">Usergrid Data model</a></li>
<li class="toctree-l1"><a class="reference internal" href="../introduction/async-vs-sync.html">Async vs. sync calls</a></li>
</ul>
<p class="caption"><span class="caption-text">Getting Started</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../getting-started/creating-account.html">Creating an Usergrid Account</a></li>
<li class="toctree-l1"><a class="reference internal" href="../getting-started/creating-a-new-application.html">Creating a new application</a></li>
<li class="toctree-l1"><a class="reference internal" href="../getting-started/using-a-sandbox-app.html">Using a Sandbox Application</a></li>
<li class="toctree-l1"><a class="reference internal" href="../getting-started/using-the-api.html">Using the API</a></li>
</ul>
<p class="caption"><span class="caption-text">Data Storage</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../data-storage/data-store-dbms.html">The Usergrid Data Store</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-storage/optimizing-access.html">Data Store Best Practices</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-storage/collections.html">Collections</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-storage/entities.html">Entities</a></li>
</ul>
<p class="caption"><span class="caption-text">Data Queries</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../data-queries/querying-your-data.html">Querying your data</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-queries/query-parameters.html">Query parameters &amp; clauses</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-queries/operators-and-types.html">Query operators &amp; data types</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-queries/advanced-query-usage.html">Advanced query usage</a></li>
</ul>
<p class="caption"><span class="caption-text">Entity Connections</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../entity-connections/connecting-entities.html">Connecting entities</a></li>
<li class="toctree-l1"><a class="reference internal" href="../entity-connections/retrieving-entities.html">Retrieving connections</a></li>
<li class="toctree-l1"><a class="reference internal" href="../entity-connections/disconnecting-entities.html">Disconnecting entities</a></li>
</ul>
<p class="caption"><span class="caption-text">Push Notifications</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/overview.html">Push notifications overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/adding-push-support.html">Adding push notifications support</a></li>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/getting-started.html">Getting started with push notifications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/tutorial.html">Tutorial: Push notifications sample app</a></li>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/registering.html">Registering with a notification service</a></li>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/creating-notifiers.html">Creating notifiers</a></li>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/managing-users-and-devices.html">Managing users and devices</a></li>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/creating-and-managing-notifications.html">Creating and managing notifications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/troubleshooting.html">Troubleshooting</a></li>
</ul>
<p class="caption"><span class="caption-text">Security &amp; Authentication</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/app-security.html">Security &amp; token authentication</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/using-permissions.html">Using permissions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/using-roles.html">Using roles</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/authenticating-users-and-application-clients.html">Authenticating users &amp; app clients</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/user-authentication-types.html">Authentication levels</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/changing-token-time-live-ttl.html">Changing token expiration (time-to-live)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/authenticating-api-requests.html">Authenticating API requests</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/revoking-tokens-logout.html">Revoking tokens (logout)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/facebook-sign.html">Facebook sign in</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/securing-your-app.html">Security best practices</a></li>
</ul>
<p class="caption"><span class="caption-text">User Management &amp; Social Graph</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../user-management/user-management.html">User management &amp; social graph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/working-user-data.html">Working with User Data</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/group.html">Working with group data</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/activity.html">Activity</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/user-connections.html">Social Graph Connections</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/user-connections.html#creating-other-connections">Creating other connections</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/messagee-example.html">App Example - Messagee</a></li>
</ul>
<p class="caption"><span class="caption-text">Geo-location</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../geolocation/geolocation.html">Geolocating your Entities</a></li>
</ul>
<p class="caption"><span class="caption-text">Assets &amp; Files</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../assets-and-files/uploading-assets.html">Uploading assets</a></li>
<li class="toctree-l1"><a class="reference internal" href="../assets-and-files/retrieving-assets.html">Retrieving assets</a></li>
<li class="toctree-l1"><a class="reference internal" href="../assets-and-files/folders.html">Folders</a></li>
</ul>
<p class="caption"><span class="caption-text">Counters &amp; Events</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="events-and-counters.html">Counters &amp; events</a></li>
<li class="toctree-l1"><a class="reference internal" href="creating-and-incrementing-counters.html">Creating &amp; incrementing counters</a></li>
<li class="toctree-l1"><a class="reference internal" href="creating-and-incrementing-counters.html#decrementing-resetting-counters">Decrementing/resetting counters</a></li>
<li class="toctree-l1"><a class="reference internal" href="creating-and-incrementing-counters.html#using-counters-hierarchically">Using counters hierarchically</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="">Retrieving counters</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#request-syntax">Request syntax</a></li>
<li class="toctree-l2"><a class="reference internal" href="#example-request">Example request</a></li>
<li class="toctree-l2"><a class="reference internal" href="#example-response">Example response</a></li>
<li class="toctree-l2"><a class="reference internal" href="#retrieving-counters-by-time-interval">Retrieving counters by time interval</a></li>
<li class="toctree-l2"><a class="reference internal" href="#id1">Request syntax</a></li>
<li class="toctree-l2"><a class="reference internal" href="#id2">Example request</a></li>
<li class="toctree-l2"><a class="reference internal" href="#id3">Example response</a></li>
</ul>
</li>
</ul>
<p class="caption"><span class="caption-text">Organizations &amp; Applications</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../orgs-and-apps/managing.html">Organization &amp; application management</a></li>
<li class="toctree-l1"><a class="reference internal" href="../orgs-and-apps/organization.html">Organization</a></li>
<li class="toctree-l1"><a class="reference internal" href="../orgs-and-apps/application.html">Application</a></li>
<li class="toctree-l1"><a class="reference internal" href="../orgs-and-apps/admin-user.html">Admin user</a></li>
</ul>
<p class="caption"><span class="caption-text">API Reference</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../rest-endpoints/api-docs.html">Methods</a></li>
<li class="toctree-l1"><a class="reference internal" href="../rest-endpoints/api-docs.html#models">Models</a></li>
<li class="toctree-l1"><a class="reference internal" href="../rest-endpoints/api-docs.html#sub-types">Sub-Types</a></li>
</ul>
<p class="caption"><span class="caption-text">Client SDKs</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../sdks/tbd.html">COMING SOON...</a></li>
</ul>
<p class="caption"><span class="caption-text">Installing the Stack</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../installation/ug1-deploy-to-tomcat.html">Usegrid 1: Deploying to Tomcat</a></li>
<li class="toctree-l1"><a class="reference internal" href="../installation/ug1-launcher-quick-start.html">Usegrid 1: Launcher Quick-start</a></li>
<li class="toctree-l1"><a class="reference internal" href="../installation/ug2-deploy-to-tomcat.html">Usergrid 2: Deploy to Tomcat</a></li>
</ul>
<p class="caption"><span class="caption-text">More about Usergrid</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../reference/presos-and-videos.html">Presentations &amp; Videos</a></li>
<li class="toctree-l1"><a class="reference internal" href="../reference/contribute-code.html">How to Contribute Code &amp; Docs</a></li>
</ul>

          
        
      </div>
      &nbsp;
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../index.html">Apache Usergrid</a>
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../index.html">Docs</a> &raquo;</li>
      
    <li>Retrieving counters</li>
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../_sources/counters-and-events/retrieving-counters.txt" rel="nofollow"> View page source</a>
          
        
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="retrieving-counters">
<h1>Retrieving counters<a class="headerlink" href="#retrieving-counters" title="Permalink to this headline">¶</a></h1>
<p>To retrieve a counter, do the following:</p>
<div class="section" id="request-syntax">
<h2>Request syntax<a class="headerlink" href="#request-syntax" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><div class="highlight"><pre>curl -X GET https://api.usergrid.com/counters?counter=&lt;counter_name&gt;
</pre></div>
</div>
<p>Parameters</p>
<table border="1" class="docutils">
<colgroup>
<col width="28%" />
<col width="72%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Parameter</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>counter_name</td>
<td>The name of the counter to be retrieved.</td>
</tr>
</tbody>
</table>
<p>More than one counter can be retrieved with a single request by
appending additional counter parameters to the request URI.</p>
</div>
<div class="section" id="example-request">
<h2>Example request<a class="headerlink" href="#example-request" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><div class="highlight"><pre>curl -X GET https://api.usergrid.com/my-org/my-app/counters?counter=button_clicks
</pre></div>
</div>
</div>
<div class="section" id="example-response">
<h2>Example response<a class="headerlink" href="#example-response" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><div class="highlight"><pre><span class="p">{</span>
  <span class="s">&quot;action&quot;</span> <span class="p">:</span> <span class="s">&quot;get&quot;</span><span class="p">,</span>
  <span class="s">&quot;application&quot;</span> <span class="p">:</span> <span class="s">&quot;f34f4222-a166-11e2-a7f7-02e81adcf3d0&quot;</span><span class="p">,</span>
  <span class="s">&quot;params&quot;</span> <span class="p">:</span> <span class="p">{</span>
    <span class="s">&quot;counter&quot;</span> <span class="p">:</span> <span class="p">[</span> <span class="s">&quot;button_clicks&quot;</span> <span class="p">]</span>
  <span class="p">},</span>
  <span class="s">&quot;uri&quot;</span> <span class="p">:</span> <span class="s">&quot;https://api.usergrid.com/your-org/your-app&quot;</span><span class="p">,</span>
  <span class="s">&quot;entities&quot;</span> <span class="p">:</span> <span class="p">[</span> <span class="p">],</span>
  <span class="s">&quot;timestamp&quot;</span> <span class="p">:</span> <span class="mi">1401310084096</span><span class="p">,</span>
  <span class="s">&quot;duration&quot;</span> <span class="p">:</span> <span class="mi">21</span><span class="p">,</span>
  <span class="s">&quot;organization&quot;</span> <span class="p">:</span> <span class="s">&quot;your-org&quot;</span><span class="p">,</span>
  <span class="s">&quot;applicationName&quot;</span> <span class="p">:</span> <span class="s">&quot;your-app&quot;</span><span class="p">,</span>
  <span class="s">&quot;count&quot;</span> <span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
  <span class="s">&quot;counters&quot;</span> <span class="p">:</span> <span class="p">[</span> <span class="p">{</span>
    <span class="s">&quot;name&quot;</span> <span class="p">:</span> <span class="s">&quot;button_clicks&quot;</span><span class="p">,</span>
    <span class="s">&quot;values&quot;</span> <span class="p">:</span> <span class="p">[</span> <span class="p">{</span>
      <span class="s">&quot;timestamp&quot;</span> <span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
      <span class="s">&quot;value&quot;</span> <span class="p">:</span> <span class="mi">9</span>
    <span class="p">}</span> <span class="p">]</span>
  <span class="p">}</span> <span class="p">]</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="retrieving-counters-by-time-interval">
<h2>Retrieving counters by time interval<a class="headerlink" href="#retrieving-counters-by-time-interval" title="Permalink to this headline">¶</a></h2>
<p>Knowing the value of a counter is useful; however, you often need to
know how the value varies over time. Fortunately, the API provides a
method for you to view this data over any time interval or level of
granularity.</p>
<p>For example, let’s say you’re incrementing a counter every time someone
launches your application. You might be interested in which days of the
week the application sees the most usage. Using the API, you can examine
the counter over a set of weeks, with the data split into daily
intervals. Using this information, you can see which are your peak days
of usage. You can also view usage across a single day, so you can see if
your application is used more in the mornings or the evenings.</p>
</div>
<div class="section" id="id1">
<h2>Request syntax<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><div class="highlight"><pre>curl -X GET https://api.usergrid.com/counters?start_time=&lt;timestamp&gt;&amp;end_time=&lt;timestamp&gt;&amp;resolution=&lt;resolution&gt;&amp;counter=&lt;counter_name&gt;
</pre></div>
</div>
<p>Parameters</p>
<table border="1" class="docutils">
<colgroup>
<col width="26%" />
<col width="74%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Parameter</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>start_time</td>
<td>The beginning of the time period to search</td>
</tr>
<tr class="row-odd"><td>end_time</td>
<td>The end of the time period to search</td>
</tr>
<tr class="row-even"><td>resolution</td>
<td>The interval at which counters are displayed.</td>
</tr>
<tr class="row-odd"><td>counter_name</td>
<td>The name of the counter to be retrieved.</td>
</tr>
</tbody>
</table>
<p>The following resolutions are supported:</p>
<ul class="simple">
<li>all</li>
<li>minute</li>
<li>five_minutes</li>
<li>half_hour</li>
<li>hour</li>
<li>six_day</li>
<li>day</li>
<li>week</li>
<li>month</li>
</ul>
<p>For example, if the interval is day, and the start time and end time
values span 4 days, you will get aggregate counts for each of the 4
days.</p>
</div>
<div class="section" id="id2">
<h2>Example request<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h2>
<p>For example, to retrieve a time range of values, with a granularity of
&#8220;day&#8221;, for a counter called &#8220;button_clicks&#8221;, the GET request would look
like this:</p>
<div class="highlight-python"><div class="highlight"><pre>curl -X GET https://api.usergrid.com/my-org/my-app/counters?start_time=1315119600000&amp;end_time=1315724400000&amp;resolution=day&amp;counter=button_clicks
</pre></div>
</div>
</div>
<div class="section" id="id3">
<h2>Example response<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><div class="highlight"><pre>{
 action: &quot;get&quot;,
    uri: &quot;http://api.usergrid.com/438a1ca1-cf9b-11e0-bcc1-12313f0204bb/counters&quot;,
    timestamp: 1315354369272,
    duration: 28,
    counters: [
        {
            name: &quot;button_clicks&quot;,
            values: [
                {
                    value: 2
                    timestamp: 1315180800000
                },
                {
                    value: 1
                    timestamp: 1315267200000
                },
                {
                    value: 1
                    timestamp: 1315353600000
                }
            ]
        }
    ]
}
</pre></div>
</div>
</div>
</div>


           </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../orgs-and-apps/managing.html" class="btn btn-neutral float-right" title="Organization &amp; application management" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="creating-and-incrementing-counters.html" class="btn btn-neutral" title="Creating &amp; incrementing counters" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2013-2015, Apache Usergrid.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../',
            VERSION:'1.0',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true
        };
    </script>
      <script type="text/javascript" src="../_static/jquery.js"></script>
      <script type="text/javascript" src="../_static/underscore.js"></script>
      <script type="text/javascript" src="../_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>